﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ProgNetComponentsDx.Controls.Editors.Design
{
    public class MultiSelectEditResultColumnEditor : ProgNetComponents.Design.Editors.BaseListEditor
    {
        protected override bool AlwaysRefreshItems
        {
            get
            {
                return true;
            }
        }
        protected override bool FillCollection(ProgNetComponents.Collections.NamedObjectCollection collection, System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context.Instance != null)
            {
                RepositoryItemMultiSelectGridEdit rep = null;
                if (context.Instance is RepositoryItemMultiSelectGridEdit)
                    rep = context.Instance as RepositoryItemMultiSelectGridEdit;
                else if (context.Instance is MultiSelectGridEdit)
                    rep = (context.Instance as MultiSelectGridEdit).Properties;
                if (rep != null)
                {
                    if (rep.ResultTable != null)
                    {
                        foreach (DataColumn col in rep.ResultTable.Columns)
                        {
                            collection.Add(col.ColumnName, col.ColumnName);
                        }
                    }
                }
            }
            return true;
        }
    }
    public class MultiSelectEditDataSourceColumnEditor : ProgNetComponents.Design.Editors.BaseListEditor
    {
        protected override bool AlwaysRefreshItems
        {
            get
            {
                return true;
            }
        }
        protected override bool FillCollection(ProgNetComponents.Collections.NamedObjectCollection collection, System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context.Instance != null)
            {
                RepositoryItemMultiSelectGridEdit rep = null;
                if (context.Instance is RepositoryItemMultiSelectGridEdit)
                    rep = context.Instance as RepositoryItemMultiSelectGridEdit;
                else if (context.Instance is MultiSelectGridEdit)
                    rep = (context.Instance as MultiSelectGridEdit).Properties;
                if (rep != null)
                {
                    if (rep.DataSourceAsTable != null)
                    {
                        foreach (DataColumn col in rep.DataSourceAsTable.Columns)
                        {
                            collection.Add(col.ColumnName, col.ColumnName);
                        }
                    }
                }
            }
            return true;
        }
    }
}
